<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/common/common.jspf" %>
<html>
<head>
    <title>My JSP 'MyJsp.jsp' starting page</title>

    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">

    <script type="text/javascript">
        $(function (){
            $('#storeTable').datagrid({
                url:'${proPath}/storetable/selectPage.action', // user/select.action
                // method:'post',
                //idfield:'productid',
                columns:[[
                    {checkbox:true},
                    {field:'tableCompanyName',title:'公司名',width:100},
                    {field:'tableStoreName',title:'店铺名',width:100},
                    {field:'tablePic',title:'二维码',width:100,align:'right',formatter:function (value,row,index) {
                        if(value!=null){

                            return  "<img src='${proPath}/tablepic/"+value+"'>";
                        }
                    }
                },
                    {field:'tableNum',title:'餐桌编号',width:100},
                    {field:'tableName',title:'餐桌名称',width:100},
                    {field:'tableSeatNum',title:'座位数',width:100},
                    {field:'tableStatus',title:'餐桌状态',width:100},
                    {field:'tableWays',title:'就餐形式',width:100},
                    {field:'tableCreate',title:'创建时间',width:100},
                    {field:'tableUpdate',title:'更新时间',width:100}
                ]],
                fitColumns:true,
                toolbar: [{
                    iconCls: 'icon-add',
                    text:'添加',
                    handler: function(){
                        //alert('添加');

                        parent.$('#win').window({
                            width:600,
                            height:300,
                            title:'添加餐桌',
                            modal:true,
                            content:"<iframe src='${proPath}/base/goURL.action?url=storetable/addTable' title='添加餐桌' height='100%' width='100%' frameborder='0px'/>"
                        });
                    }
                },'-',{
                    iconCls: 'icon-edit',
                    text:'修改',
                    handler: function(){
                        //判断，只能选择一行
                        var array = $('#storeTable').datagrid("getSelections");
                        if(array.length<1){
                            alert("请选择");
                            return ;
                        }

                        if(array.length>1){
                            alert("只能选择一个");
                            return ;
                        }
                        //alert(array[0].tableId+","+array[0].tableName+","+array[0].tableWays);
                        parent.$('#win').window({
                            width:600,
                            height:300,
                            title:'修改餐桌',
                            modal:true,
                            content:"<iframe src='${proPath}/base/goURL.action?url=storetable/updateTable' title='修改餐桌' height='100%' width='100%' frameborder='0px'/>"
                        });
                    }
                },'-',{
                    iconCls: 'icon-add',
                    text:'预约餐桌',
                    handler: function(){
                        //alert('预约餐桌按钮');
                        //判断，只能选择一行
                        var array = $('#storeTable').datagrid("getSelections");
                        if(array.length<1){
                            alert("请选择");
                            return ;
                        }

                        if(array.length>1){
                            alert("只能选择一个");
                            return ;
                        }
                        if(array[0].tableStatus =="禁用"  ){
                            alert("该餐桌已被禁用不可预约，请重新选择");
                            return ;
                        }

                        if(array[0].tableWays =="拼桌"  ){
                            alert("拼桌不能预约");
                            return ;
                        }
                        if(array[0].tableWays == "整桌"){
                            parent.$('#win').window({
                                width:600,
                                height:420,
                                title:'预约餐桌',
                                modal:true,
                                content:"<iframe src='${proPath}/base/goURL.action?url=storetable/bookTable' title='预约餐桌' height='100%' width='100%' frameborder='0px'/>"
                            });
                        }
                    }
                },'-',{
                    iconCls: 'icon-no',
                    text:'禁用',
                    handler: function(){
                        /*location.href='/storetable/selectPage.action'*/ //有去无回
                        //判断，只能选择一行
                        checkRow();
                        var row =$('#storeTable').datagrid("getSelected");
                        if(row.tableStatus == "禁用"){
                            alert("该餐桌已禁用，请重新选择");
                            return ;
                        }
                        if(row.tableStatus == "可用"){
                            $.messager.confirm('禁用对话框', '您想要禁用该餐桌吗？', function(r){
                                if (r){
                                    // 发起ajax请求
                                    $.ajax({
                                        type: "post",
                                        url:"${proPath}/storetable/updateDisable.action",
                                        data:{tableId: row.tableId},
                                        dataType: "json",
                                        success: function (data) {
                                            search();
                                            //$('#storeTable').datagrid("getSelected");
                                        }
                                    });
                                }
                            });
                        }
                    }
                },'-',{
                    iconCls: 'icon-ok',
                    text:'启用',
                    handler: function(){
                        //判断，只能选择一行
                       checkRow();
                        var row =$('#storeTable').datagrid("getSelected");
                        if(row.tableStatus == "可用"){
                            alert("该餐桌已启用，请重新选择");
                            return ;
                        }
                        if(row.tableStatus == "禁用"){
                            $.messager.confirm('启用', '您想要启用该餐桌吗？', function(r){
                                if (r){
                                    var row =$('#storeTable').datagrid("getSelected");
                                    //alert(row.tableId);
                                    // 发起ajax请求
                                    $.ajax({
                                        type: "post",
                                        url:"${proPath}/storetable/updateAble.action",
                                        data:{tableId: row.tableId},
                                        dataType: "json",
                                        success: function (data) {
                                            search();
                                        }
                                    });
                                }
                            });
                        }

                    }
                },'-',{
                    iconCls: 'icon-save',
                    text:'部分下载',
                    handler: function(){
                        var array = $('#storeTable').datagrid("getSelections");
                        if(array.length<1){
                            alert("请选择");
                            return ;
                        }
                        if (array.length>1){
                            var rows = $('#storeTable').datagrid("getSelected");
                            alert(rows.tableNum+rows.tableName);
                        }
                    }
                },'-',{
                    iconCls: 'icon-save',
                    text:'全部下载',
                    handler: function(){
                        alert('全部下载按钮');
                    }
                }],
                striped:true,
                rownumbers:true,
                pagination:true,
                pageNumber:10,
                pageside:5,
                pageList:[5,10,15,20,25]
                /* queryParams: {
                 userName: 'easyui',
                 userAddress: 'datagrid'
                 } */
            });
            $('#tableStoreName').combobox('readonly', true);
            search();
        });

        function checkRow() {
            //判断，只能选择一行
            var array = $('#storeTable').datagrid("getSelections");
            if(array.length<1){
                alert("请选择");
                return ;
            }

            if(array.length>1){
                alert("只能选择一个");
                return ;
            }
        }

        function search() {
            /*alert($('#tableCompanyName').combobox("getText")+ $('#tableStoreName').combobox("getValue")+$('#tableStatus').combobox("getValue")+$('#tableWays').combobox("getValue")
            +$('#tableNum').val()+$('#tableName').val()+$('#tableSeatNum').val());*/
            $('#storeTable').datagrid( 'load',{
             tableCompanyName: $('#tableCompanyName').combobox("getText"),//$('#tableCompanyName').val(),
             tableStoreName: $('#tableStoreName').combobox("getText"),
             tablePic: $('#tablePic').val(),
             tableNum: $('#tableNum').val(),
             tableName: $('#tableName').val(),
             tableSeatNum:$('#tableSeatNum').val(),
             tableStatus: $('#tableStatus').combobox("getValue"),//$('#tableStatus').combobox('getText'),
             tableWays:$('#tableWays').combobox("getValue"),
             tableCreate: $('#tableCreate').val(),
             tableUpdate: $('#tableUpdate').val()
             });
        }
    </script>
<body>
<form id="search">

        <label >总公司：</label>
        <select class="easyui-combobox" id="tableCompanyName" name="tableCompanyName">
               <c:forEach items="${applicationScope.sysParamMap.table_company_name}"  var="sp">
                   <option value="${sp.key}">${sp.value}</option>
               </c:forEach>
        </select>


        <label >店铺名称：</label>
        <select class="easyui-combobox" id="tableStoreName" name="tableStoreName"  >
            <c:forEach items="${applicationScope.sysParamMap.table_name}"  var="s">
                <option value="${s.key}">${s.value}</option>
            </c:forEach>
        </select>


        <label >餐桌编号：</label>
        <input class="easyui-validatebox" type="text" id="tableNum" name="tableNum"/>
    <div>

        <label >餐桌名称：</label>
        <input class="easyui-validatebox" type="text" id="tableName" name="tableName" />

        <label >座位数：</label>
        <input class="easyui-validatebox" type="text" id="tableSeatNum" name="tableSeatNum" />

        <label >就餐形式：</label>
        <select  class="easyui-combobox" id="tableWays" name="tableWays" >
            <option value="">--请选择--</option>
            <option>整桌</option>
            <option>拼桌</option>
        </select>
        <label >状态：</label>
        <select  class="easyui-combobox" id="tableStatus" name="tableStatus">
            <option>可用</option>
            <option>禁用</option>
            <option value="">全部</option>
        </select>
    <input type="button" onclick="search()" value="查询">
    </div>

</form>
<table id="storeTable"></table>




</body>
</html>